package c2.group.business.demo;

import c2.advanced.business.base.AdvancedSubModule;
import c2.advanced.business.base.KvData;
import c2.advanced.business.demo.DemoStatus;
import c2.advanced.business.demo.handler.DemoMailHandler;
import c2.advanced.business.demo.handler.DemoPlayHandler;
import c2.advanced.business.demo.handler.DemoRpcHandler;
import c2.group.business.GroupBody;
import c2.group.business.base.GroupModule;
import lombok.extern.slf4j.Slf4j;

/** 跨服演示总模块 */
@Slf4j
public class DemoModule extends GroupModule<DemoStatus> {

    private DemoRpcHandler rpcSM = new DemoRpcHandler();
    private DemoPlayHandler playSM = new DemoPlayHandler();
    private DemoMailHandler mailSM = new DemoMailHandler();

    @Override
    protected AdvancedSubModule[] getSubModules() {
        return new AdvancedSubModule[] { rpcSM, playSM, mailSM };
    }

    @Override
    protected String getStatusKey() {
        return KvData.KEY_DEMO;
    }

    @Override
    protected Class<DemoStatus> getStatusClass() {
        return DemoStatus.class;
    }

    public DemoModule(GroupBody context) {
        super(context);
    }

    @Override
    public String getName() {
        return "演示功能";
    }


    @Override
    protected void onInterval() throws Exception {
        //log.info("演示功能onInterval()");
    }

    public Object doDb() {
        return db().demo.findBooksByType("zh");
    }

    public Object doRpc() throws Exception {
        return rpcSM.play();
    }

    public Object doTable() throws Exception {
        return table().ladder.robot.list;
    }

    public Object doPlay() {
        return playSM.createPlaySideByDynCfg();
    }

    public Object doMailSendToGame(int demo) {
        return mailSM.doMailSendToGame(demo);
    }

    @Override
    protected void onShutdownBeforeSubModules() {
        log.info("演示模块onShutdownBeforeSubModules()");
    }

    @Override
    protected void onShutdownAfterSubModules() {
        log.info("演示模块onShutdownAfterSubModules()");
    }
}